package com.jacen.fzxs.service.app.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import jodd.util.StringUtil;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jacen.fzxs.entity.WallEntity;
import com.jacen.fzxs.entity.web.AppEntity;
import com.jacen.fzxs.entity.web.Wall;
import com.jacen.fzxs.exception.WebException;
import com.jacen.fzxs.service.IWallService;
import com.jacen.fzxs.util.Constants;
import com.jacen.fzxs.web.Pager;

@Service
@Transactional(rollbackFor = Exception.class)
public class WallHandlerService extends BaseHandlerService {
	@Resource
	private IWallService wallService;

	@Override
	protected AppEntity submit(AppEntity appEntity,HttpServletRequest request) throws WebException {
		AppEntity resAppEntity = new AppEntity();
		Pager pager = appEntity.getPager();
		Map<String, String> params = new HashMap<String, String>();
		String userName = appEntity.getUserName();
		String tel = appEntity.getTel();
		String address = appEntity.getAddress();
		if(!StringUtil.isEmpty(userName)){
			params.put("userName", userName);
		}
		if(!StringUtil.isEmpty(tel)){
			params.put("tel", tel);
		}
		if(!StringUtil.isEmpty(address)){
			params.put("address", address);
		}
		if(pager!=null){
			pager.setPageSize(Constants.PAGE_SIZE);
		}
		List<WallEntity> list = wallService.getListPage(pager, params);
		List<Wall> walls = Wall.turnToWallList(list);
		resAppEntity.setWallList(walls);
		resAppEntity.setPager(pager);
		return resAppEntity;
	}

}
